import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // 配置按需导入插件 自动导入插件
    AutoImport({
      resolvers: [ElementPlusResolver()
      ]
    }),
    Components({
      resolvers: [ElementPlusResolver()
      ]
    })
  ],
  
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server:{
    port:8080,
    proxy: {
      '/api': {
        target: 'http://localhost:8888/', //目标url
        changeOrigin: true, // 支持跨域
        logLevel: 'debug', // 后端打印真实端口
        rewrite: (path) => path.replace(/^\/api/, '') // 重写路径,替换/api
      }
    }
    // open: true // 设置服务启动时是否自动打开浏览器
  }
})
